package com.qk.management.mapper;

import com.qk.dto.user.UserDTO;
import com.qk.entity.User;
import com.qk.vo.user.UserVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 *
 * @author lyl
 * @created 2025/9/30 15:23
 * @description
 *
 */
@Mapper
public interface UserMapper {

    List<UserVO> list(UserDTO userDTO);

    @Insert("insert into user(username,password,name,phone,email,gender,status,dept_id,role_id,image,remark,create_time,update_time) values(#{username},#{password},#{name},#{phone},#{email},#{gender},#{status},#{deptId},#{roleId},#{image},#{remark},#{createTime},#{updateTime})")
    void addUser(User user);

    @Select("select * from user where dept_id = #{deptId}")
    List<User> listByDept(Integer deptId);

    @Select("select u.id,u.username,u.name,u.phone,u.email,u.gender,u.status,u.dept_id,u.role_id,u.image,u.remark,u.create_time,u.update_time from user u inner join role r on u.role_id = r.id where r.label = #{roleLabel}")
    List<User> listByRole(String roleLabel);

    @Select("select * from user")
    List<User> getAll();

    @Update("update user set username = #{username},name = #{name},phone = #{phone},email = #{email},gender = #{gender},status = #{status},dept_id = #{deptId},role_id=#{roleId},image=#{image},remark=#{remark},create_time=#{createTime},update_time=#{updateTime} where id = #{id}")
    void updateUser(User user);

    @Select("select * from user where id = #{id}")
    User getUserById(Integer id);

    void deleteUsers(List<Integer> ids);

    @Select("select * from user where username = #{username}")
    User getUserByUsername(String username);

    @Select("select image from user")
    List<String> getImages();

}
